<div class="head">
<h5 class="iList">Frontend Label Definition (English)</h5>
</div>
<form
	action=""
	method="post" id="valid" class="mainForm"
	<?php $form->isMultipart() and print 'enctype="multipart/form-data" ' ?>>

<div class="rowElem noborder"><label for="name">Name:</label> 

<div class="formRight"><input style="" type="text"
	name="frontend_labels[name]"
	value="<?php echo $form->getObject()->getName()?>"
	class="validate[required]" id="frontend_labels_name" />
</div>

<div class="fix"></div>
</div>

<div class="fix"></div>
		 <input type="button" value="Save" class="greyishBtn submitForm" id="save" /> 
<div class="fix"></div>

<input type="hidden" name="frontend_labels[language_id]" value="<?php echo sfConfig::get('app_english')?>">

</form>


<script type="text/javascript">

$("#save").click(function (event){
    submitForm();
})

$("form#valid").submit(function (event){
    event.preventDefault();
    submitForm();
})


function submitForm(){
    var str=$('form#valid').serialize();

    $.ajax({type: 'POST', url:' <?php echo url_for('frontend_labels/'.($form->getObject()->isNew() ? 'create' :'update').
    (!$form->getObject()->isNew() ? '?id='.$form->getObject()->getId() : ''))?>', script:true, cache:false, data:  str, 
    beforeSend: function(){
				    	if (!validate()){
							return false;
				        }
						},
            success: function(data) {
                 $('#label_container_div').html(data);
                 $('#frontend_labels_name').attr('value',"");
                 $("div[class^='widget']").simpleTabs();
                 $("select, input:checkbox, input:radio, input:file").uniform();
             } });
}


function validate(){
	var valid = true;
	var error_msg = "";
	if ($("#frontend_labels_name").attr("value") == ""){
		valid = false;
		error_msg = "Name required";
	}

	else if(valid && $('option:selected', '#frontend_labels_language_id').index() == 0){
		valid = false;
		error_msg = "Language required";
	}	
		
	if (!valid){
		$('#msg_text').html(error_msg);
		$('#error_msg').show('fast');
	}
	return valid;			
}

</script>
